package com.vortex;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Configurable;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;

/**
 * Created by machine on 2017/7/6.
 */
@Configurable
public class PreFilter extends ZuulFilter {

	private Logger logger = LoggerFactory.getLogger(PreFilter.class);

	@Override
	public String filterType() {
		return "pre";
	}

	@Override
	public int filterOrder() {
		return 5;
	}

	@Override
	public boolean shouldFilter() {
		return true;

	}

	@Override
	public Object run() {

		RequestContext ctx = RequestContext.getCurrentContext();
		String refresh_token = ctx.getRequest().getParameter("refresh_token");
		// 校验access_token ，如果token无效就要过滤
		logger.error("refresh_token:" + refresh_token);
		// String access_token="access_token";

		// refresh_token并且获取到他

		String access_token = refresh_token(refresh_token);
		return null;

	}

	private String refresh_token(String refresh_token) {
		return refresh_token;
		// TODO Auto-generated method stub

	}
}
